$(function () {
    // 课程分类下拉框
    $('.selected0').click(function () {
        $('.selected').slideToggle()
    })
    $.ajax({
        url: 'http://yapi.shangyuninfo.com/mock/131/weChat/applet/subject/list',
        type: 'post',
        contentType: 'application/json',
        data: JSON.stringify({
            'enable': 1,
        }),
        success: function (res) {
            console.log('123')
        }
    })

    // 课程分类配置列表
    $.ajax({
        url: 'http://59.111.104.104:8086/weChat/applet/subject/list',
        type: 'post',
        contentType: 'application/json',
        data: JSON.stringify({
            'enable': 1,
        }),
        success: function (res) {
            console.log(res)
            for (var j = 0; j < $('.selected li').length; j++) {
                $('.selected li').eq(j).html(res.rows[j].title)
            }
        }

    })
    // 直播课程
    for (var i = 0; i < $('.current1').length; i++) {
        $('.current1').eq(i).mouseover(function () {
            $('.current1').css({
                'color': '#000000',
                'border-Left': '5px solid #F4F4F4',
                'backgroundColor': '#F4F4F4',
                'width': ''
            })
            $(this).css({
                'color': '#00CF8C',
                'border-Left': '5px solid #00CF8C',
                'backgroundColor': 'white',
                'width': '99%'
            })
            $('.boxFourLeft').css('display', 'none')
            $('.boxFourLeft').eq($(this).index()).css('display', 'block')
        })
    }

    // 右上登录 包含遮罩层
    $('#denglu').click(function () {
        $('.backgroundBox').show()
    })
    $('#close').click(function () {
        $('.backgroundBox').hide()
    })
    $('#span2').click(function () {
        $('#dengLubox_Left').css('display', 'none')
        $('.dengLubox_Right').css('display', 'block')
        $('#span2').css({
            'border-bottom': '2px solid #00CF8C',
            'color': '#00CF8C'
        })
        $('#span1').css({
            'color': 'rgba(0,0,0,.65)',
            'border-bottom': '0px'
        })
    })
    $('#span1').click(function () {
        // console.log('123')
        $('#dengLubox_Left').css('display', 'block')
        $('.dengLubox_Right').css('display', 'none')
        $('#span1').css({
            'border-bottom': '2px solid #00CF8C',
            'color': '#00CF8C'
        })
        $('#span2').css({
            'color': 'rgba(0,0,0,.65)',
            'border-bottom': '0px'
        })
    })
    $('.background').click(function () {
        $('.backgroundBox').hide()
    })
})
// 上方轮播
$(function () {
    var timer = setInterval(loop, 1500);
    var num = 0;

    function loop() {
        num++;
        if (num == 5) {
            $('.boxThree').css('left', 0)
            num = 1;
        }
        $('.boxThree').stop().animate({
            'left': -1518 * num
        })
    }
    $(".right").click(function () {
        clearInterval(timer)
        loop()
    })

    function loopR() {
        num--;
        if (num == -1) {
            $('.boxThree_inner').css('left', -1518 * 3)
            num = 2;
        }
        $('.boxThree_inner').stop().animate({
            'left': -1518 * (num) - 1
        })
    }
    $(".left").click(function () {
        clearInterval(timer)
        loopR()
    })
    $(".boxThree").mouseover(function () {
        clearInterval(timer)
    })
    $(".boxThree").mouseout(function () {
        timer = setInterval(loop, 1000)
    })
})

$(function () {
    // 免费课程
    $.post("http://59.111.104.104:8086/weChat/applet/course/list/type", {
        "type": 'free',
        "pageNum": 1,
        "pageSize": $('.free_sourse_img').length
    }, function (data) {
        // console.log(data.rows)
        for (var i = 0; i < $('.free_sourse_img').length; i++) {

            $('.free_sourse_img').eq(i).attr('src', data.rows[i].bannerFileUrl)
            $('.free_in_cont_line_tit').eq(i).html(data.rows[i].courseTitle)
            $('.free_in_cont_line_data').eq(i).html('共' + data.rows[i].subSectionNum + '节课|' + data.rows[i].participationsCount + '报名')
            
        }
    })
    // console.log($('.free_in_cont_line_tit').length)
    // 精品课程
    $.post("http://59.111.104.104:8086/weChat/applet/course/list/type", {
        "type": 'boutique',
        "pageNum": 1,
        "pageSize": 5
    }, function (data) {
        // console.log(data.rows)
        for (var i = 0; i < $('.jingpin_sourse_img').length; i++) {
            $('.jingpin_sourse_img').eq(i).attr('src', data.rows[i].bannerFileUrl)
            $('.jingpin_in_cont_line_tit').eq(i).html(data.rows[i].courseTitle)
            $('.jingpin_in_cont_line_data').eq(i).html('共' + data.rows[i].subSectionNum + '节课|' + data.rows[i].participationsCount + '报名')
            $('.jingpin_in_cont_line_newprice').eq(i).html('￥' + data.rows[i].discountPrice)
            $('.jingpin_in_cont_line_price').eq(i).html('￥' + data.rows[i].coursePrice)
        }
    })

    // 限时折扣课程
    $.post("http://59.111.104.104:8086/weChat/applet/course/list/type", {
        "type": 'discount',
        "pageNum": 1,
        "pageSize": 5
    }, function (data) {
        // console.log(data.rows)

        for (var i = 0; i < $('.xianshi_sourse_img').length; i++) {
            // console.log(data.rows[i].discountPrice)
            $('.xianshi_sourse_img').eq(i).attr('src', data.rows[i].bannerFileUrl)
            $('.xianshi_in_cont_line_tit').eq(i).html(data.rows[i].courseTitle)
            $('.xianshi_in_cont_line_data').eq(i).html('共' + data.rows[i].subSectionNum + '节课|' + data.rows[i].participationsCount + '报名')
            $('.xianshi_in_cont_line_newprice').eq(i).html('￥' + data.rows[i].discountPrice)
            $('.xianshi_in_cont_line_price').eq(i).html('￥' + data.rows[i].coursePrice)
        }
    })

})